package util.collection.releventapi;

import org.apache.commons.collections4.CollectionUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author 李栋
 * @version 1.0.0
 * @className CollectionUtils.java
 * @createTime 2021年05月19日 21:51:00
 */
public class CollectionUtilTest {

    private static final Logger logger = LoggerFactory.getLogger(CollectionUtilTest.class);

    @Test
    public void test() {
        List<String> list1 = Arrays.asList("a", "b", "c");
        List<String> list2 = Arrays.asList("c", "d", "e");

        // 交集
        List<String> union = new ArrayList<>(CollectionUtils.union(list1, list2));
        // 增加的
        List<String> add = CollectionUtils.subtract(union, list1).stream().collect(Collectors.toList());
        // 减少的
        List<String> sub = CollectionUtils.subtract(list1, list2).stream().collect(Collectors.toList());
        logger.info("增加的：{}", add);
        logger.info("减少的：{}", sub);
    }


}
